package com.example.his.api.mis.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.example.his.api.db.dao.SystemDao;
import com.example.his.api.db.pojo.SystemEntiy;
import com.example.his.api.mis.service.SystemService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Service("MisSystemService")
public class SystemServiceImpl implements SystemService {
  @Resource
  private SystemDao systemDao;
  
  @Resource
  private RedisTemplate redisTemplate;
  
  @Override
  public ArrayList <SystemEntiy> searchAll() {
    ArrayList <SystemEntiy> list = systemDao.searchAll();
    return list;
  }
  
  @Override
  public String getItemValue(String item) {
    String key = "setting#" + item;
    String value = redisTemplate.opsForValue().get(key).toString();
    return value;
  }
  
  @Override
  @Transactional
  public Integer insert(Map param) {
    SystemEntiy bean = BeanUtil.toBean(param, SystemEntiy.class);
    systemDao.insert(bean);
    Integer id = bean.getId();
    return id;
  }
  
  @Override
  @Transactional
  public int deleteByIds(Integer[] ids) {
    int i = systemDao.deleteByIds(ids);
    return i;
  }
  
  @Override
  @Transactional
  public boolean update(Map map) {
    int rows = systemDao.update(map);
    return rows == 1;
  }
  
  @Override
  public HashMap searchById(Integer id) {
    HashMap map = systemDao.searchById(id);
    return map;
  }
}
